<?php

namespace IDock\Insurance\CHAC\Response;

use IDock\Http\Response;

class AllCHACResponse extends Response
{
    protected $records = [];

    public $result = [];

    public $urlDecode = false;

    public function resolve(): Response
    {
        $this->result = $this->getBody();

        if ($this->printer and is_string($this->printer)) {
            $this->printer = new $this->printer;
        }

        if ($this->urlDecode) {
            $this->urlDecodeJsonResolve();
        }

        return $this;
    }

    private function urlDecodeJsonResolve()
    {
        $data = urldecode($this->getBody());

        $this->result = $data;

        if (json_decode($data)) {
            $this->setBody(json_decode($data,true));
            return;
        }

        $this->setBody($data);

    }
}
